package com.breeze.algorithm.sort;

import java.util.Arrays;

/**
 * 选择排序
 * @author yangzh
 * @date 2025/5/21
 */
public class SelectionSort {
    public static void main(String[] args) {
        int[] numbs = {2, 2, 4, 3, 7, 5, 1};
        SelectionSort.selectionSort(numbs);
        System.out.println(Arrays.toString(numbs));
    }

    public static void selectionSort(int[] numbs) {
        int cursor = 0, minIndex, temp;
        while(cursor < numbs.length - 1) {
            minIndex = cursor;
            for (int i = cursor + 1; i < numbs.length; i++) {
                if (numbs[i] < numbs[minIndex]) {
                    minIndex = i;
                }
            }
            temp = numbs[cursor];
            numbs[cursor] = numbs[minIndex];
            numbs[minIndex] = temp;
            cursor++;
        }
    }
}
